<?php

// +----------------------------------------------------------------------
// | ThinkAdmin
// +----------------------------------------------------------------------
// | 版权所有 2014~2019 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
// +----------------------------------------------------------------------
// | 官方网站: http://demo.thinkadmin.top
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 代码仓库：https://gitee.com/zoujingli/ThinkAdmin
// | github 代码仓库：https://github.com/zoujingli/ThinkAdmin
// +----------------------------------------------------------------------

namespace app\admin\controller;

use app\admin\service\NodeService;
use library\Controller;
use library\tools\Data;
use think\Console;
use think\Db;
use think\exception\HttpResponseException;

require_once '../vendor/baiduocr/AipOcr.php';
use AipOcr;

const APP_ID = '87370094';
const API_KEY = 'MdPgc6TuoKPpoWZR1K0cFrAM';
const SECRET_KEY = 'Jzc5vlIDbVNZQ3L975kJKDrLVcnZtKk7';

/**
 * 百度OCR demo
 * Class demoScript
 * @package app\admin\controller
 */
class Demo extends Controller
{

    /**
     * 病历图片转文字
     */
    public function ocr()
    {
        $client = new AipOcr(APP_ID, API_KEY, SECRET_KEY);

        // 调用百度0CR文字识别API
        $image  = file_get_contents('https://aiwenzhen.oss-cn-chengdu.aliyuncs.com/2024-06-26/49a55c5d-5cc2-4094-82de-116f43236543140234.jpg');
        // $result = $client->basicGeneral($image);

        $url = 'https://aiwenzhen.oss-cn-chengdu.aliyuncs.com/2024-06-26/49a55c5d-5cc2-4094-82de-116f43236543140234.jpg';
        // 调用通用文字识别, 图片参数为远程url图片
        // $result = $client->basicGeneralUrl($url);

        dump($result);die;

        //解析识别结果
        if(isset($result['words_result'])){
            foreach($result['words_result'] as $word){
                echo $word['words'] . "";
            }
        } else{
            echo "文字识别失败";
        }
        var_dump($client);die;
    }
}
